
cc.Class({
    extends: cc.Component,

    properties: {
        remote:'',
        wxUrl : ''
    },

    start () {
        var sp = this.node.getComponent(cc.Sprite);
        this.createImage(function(sf){
            sp.spriteFrame = sf
        })
    },

    createImage(cb){
        if(CC_WECHATGAME){
            let image = wx.createImage();
                image.onload = () => {
                    try {
                        let texture = new cc.Texture2D();
                        texture.initWithElement(image);
                        texture.handleLoadedTexture();
                        cb(new cc.SpriteFrame(texture));
                    } catch (e) {
                        cb(null)
                    }
                };
                image.src = this.wxUrl;
        } else {
            cc.loader.load({
                url: this.remote, type: 'png'
            }, (err, texture) => {
                cb(new cc.SpriteFrame(texture))
            });
        }
    }

    // update (dt) {},
});
